<?php
namespace Shop\Controller;
use Think\Controller;

class VerifycodeController extends \Org\Util\AdminController {
    /**
     * CRUD前后置操作
     */
    public function interfaceBeforeCreate() {
    }
    public function interfaceAfterCreate($id) {
    }
    public function interfaceBeforeDelete($id) {
    }
    public function interfaceAfterDelete($id) {
    }
    public function interfaceBeforeUpdate($id) {
    }
    public function interfaceAfterUpdate($id) {
    }

    /**
     * list页面按钮接口
     * return $html
     */
    public function tableOpeationButton() {
    	return "";
    }
    public function wapTableOpeationButton() {
    	return "";
    }
    
    /**
     * 父类中已经有典型的CRUD操作并预留入口
     * 如有较大改动则覆盖一下
     */
    public function create() {
        parent::create();
    }

    public function delete() {
        parent::delete();
    }

    public function update($id=0) {
        parent::update($id);
    }

    public function list() {
        //$_GET['searchMap']['user_id'] = session('商家')['id'];
        $fundinglist = D('funding')->where(['user_id' => session('商家')['id']])->select();
        $tmp[] = 0;
        foreach($fundinglist as $v) {
            $tmp[] = $v['id'];
        }
        if (!empty($_GET['searchMap']['funding_id'])) {
            if (in_array($_GET['searchMap']['funding_id'], $tmp)) {
                unset($tmp);
                $tmp[] = $_GET['searchMap']['funding_id'];
            } else {
                unset($tmp);
                $tmp[] = 0;
            }
        }
        $_GET['searchMap']['funding_id'] = array('IN', implode(',', $tmp));
        $_GET['searchMap']['order_type'] = 'Funding';
        parent::list();
    }

    public function detail($id = 0) {
        parent::detail($id);
    }

    public function import() {
        parent::import();
    }

    public function export() {
        parent::export();
    }

    public function changestate() {
        $id = intval($_GET['id']);
        $model = D('verifycode')->find($id);
        if ($model['state'] == '未使用') {
            $model['state'] = '已使用';
        } else {
            $model['state'] = '未使用';
        }
        D('verifycode')->where(['id'=>$id])->save($model);
        $this->success('修改成功');
    }
}
